package com.fgxia.admin.controller.web;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.fgxia.admin.service.IAdminOrderService;
import com.ruoyi.business.domain.bo.admin.AdminOrderQueryBo;
import com.ruoyi.business.domain.vo.OrderInfoVo;
import com.ruoyi.business.domain.vo.SysUserExportVo;
import com.ruoyi.business.domain.vo.admin.AdminOrderExportVo;
import com.ruoyi.business.domain.vo.admin.AdminOrderQueryVo;
import com.ruoyi.business.domain.vo.admin.AdminOrderRevaluationVo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * web端订单管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/order")
public class WebOrderController extends BaseController {

    @Autowired
    private final IAdminOrderService orderService;

    /**
     * 获取订单列表
     */
    @SaCheckPermission("order:order:list")
    @GetMapping("/list")
    public TableDataInfo<OrderInfoVo> listOrder(AdminOrderQueryBo orderQueryBo, PageQuery pageQuery) {
        return orderService.listOrder(orderQueryBo, pageQuery);
    }

    /**
     * 获取订单详情
     */
    @SaCheckPermission("order:order:query")
    @GetMapping("/{orderId}")
    public R<AdminOrderQueryVo> getOrder(@PathVariable Long orderId) {
        return R.ok(orderService.queryOrderById(orderId));
    }

    /**
     * 订单改价记录列表
     */
    @SaCheckPermission("order:price:list")
    @GetMapping("/price/{orderId}")
    public R<AdminOrderRevaluationVo> listOrderPrice(@PathVariable Long orderId) {
        return R.ok(orderService.listOrderPrice(orderId));
    }

    /**
     * 导出订单列表
     */
    @SaCheckPermission("order:order:export")
    @PostMapping("/export")
    public void exportOrder(AdminOrderQueryBo orderQueryBo, HttpServletResponse response) {
        List<AdminOrderExportVo> listVo = orderService.listExportOrder(orderQueryBo);

        ExcelUtil.exportExcel(listVo, "用户数据", AdminOrderExportVo.class, response);
    }
}
